﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IGolovkine.AoA.BinarySerialization;

namespace IGolovkine.AoA.Tcp
{
    [Serializable]
    public class AcceptTcpConnections : TcpMessage
    {
        private readonly int _sourcePort;
        private readonly string _destinationHost;
        private readonly int _destinationPort;

        public AcceptTcpConnections(int sourcePort, string destinationHost, int destinationPort)  
        {
            _sourcePort = sourcePort;
            _destinationHost = destinationHost;
            _destinationPort = destinationPort;
        }

        protected AcceptTcpConnections(IBinaryReader reader) : base(reader)
        {
            _sourcePort = reader.ReadInt32();
            _destinationHost = reader.ReadString();
            _destinationPort = reader.ReadInt32();
        }

        public int SourcePort
        {
            get { return _sourcePort; }
        }

        public string DestinationHost
        {
            get { return _destinationHost; }
        }

        public int DestinationPort
        {
            get { return _destinationPort; }
        }

        public override void Serialize(IBinaryWriter writer)
        {
            base.Serialize(writer);
            writer.WriteInt32(_sourcePort);
            writer.WriteString(_destinationHost);
            writer.WriteInt32(_destinationPort);
        }

        public override string ToString()
        {
            return string.Format("{0}: Source Port = {1}, Destination Host = {2}:{3}", this.GetType().Name, _sourcePort, _destinationHost);
        }
    }
}
